import cTitle from "components/title";
import { Toast } from 'vant';
import { scrollMixin } from "utils/mixin";
let listURL = "member.member.advertisementList";
// let pageURL = "plugin.love.Frontend.Controllers.page.index"
export default {
  mixins: [scrollMixin], //加载更多
  data() {
    return {
      selected: "0",
      pagesize: 1,
      loading: false,
      allLoaded: false,
      goload: true,
      isLoadMore: true,
      page: 1,
      total_page: 0,
      video_active_url:"",
      video_active:false,
      video_active_id:"",
      // 全部
      allData: [],
      income_name_text: "",

      active:false,
    };
  },
  computed: {
  },
  methods: {
    play(id,url){
      console.log(id,url);
      this.video_active_id = id
      this.video_active_url = 'https://hdxdsc.ashdyt.com/static/upload/' + url
      this.video_active = true;
      let that = this;
      this.$nextTick(()=>{
        that.$refs.adsVideo.play()
      })
    },

    closeVideo(){
      console.log("asldfia")

      

      var that = this;
      let second = 10;
      
      if(that.active){
        Toast("正在释放中！")
        return
      }
      that.$toast.loading({
        duration: 0, // 持续展示 toast
        forbidClick: true,
        message: '正在释放中...',
      });
      that.active = true

      $http
        .get(
          'member.member.advertisement',
          { attachment_id : that.video_active_id},
          "正在获取"
        )
        .then(
          function (response) {
            
            
            if (response.result == 1) {
              Toast.clear()
              that.active = false
              if(response.msg == '已释放当日绿色积分'){
                
                Toast("已释放")               
              }
              
              that.video_active = false;
              that.video_active_id = ""
              that.video_active_url = ""
            } else {
              that.active = false
              Toast.clear()
              that.video_active = false;
              that.video_active_id = ""
              that.video_active_url = ""
              that.$dialog.alert({message:response.msg});
            }  
            
            
          },
          function (response) {
            // error callback
          }
        );

    },
    initData() {
      this.page = 1;
      this.total_page = 0;
      this.goload = true;
      this.loading = true;
      this.allLoaded = false;
      this.isLoadMore = true;

      this.allData = [];
    },

    // 切换优惠券状态列表
    switchItem() {
      // this.initData()
      this.getNetData();
    },

    // 发起http请求
    getNetData() {
      var that = this;
      $http
        .get(
          listURL,
          { page: 1 },
          "正在获取"
        )
        .then(
          function (response) {
            if (response.result == 1) {
              var myData = response.data;
              that.allData = [];
              that.allData = myData;
              that.isLoadMore = true;
              that.page = 1;
              that.total_page = response.data.last_page;
              if (!that.total_page) {
                that.total_page = 0;
              }
            } else {
              that.$dialog.alert({message:response.msg});
              // Toast(response.msg)
            }
          },
          function (response) {
            // error callback
          }
        );
    },
    getMoreData() {
      var that = this;
      this.isLoadMore = false;// 防止多次请求分页数据
      if (this.page >= this.total_page) {
        return;
      } else {
        this.page = this.page + 1;
        $http
          .get(
            listURL,
            { service_type: this.selected, page: this.page },
            "正在获取更多订单"
          )
          .then(
            function (response) {
              if (response.result == 1) {
                that.isLoadMore = true;
                var myData = response.data;
                that.allData = that.allData.concat(myData.data); // 数组拼接
              } else {
                that.page = that.page - 1;
                that.isLoadMore = false;
                return;
              }
            },
            function (response) {
              // error callback
            }
          );
      }
    },    
    //自定义提现收入语言
    customizeIncome() {
      let mailLanguage = this.fun.initMailLanguage();
      //自定义收入字段
      this.income_name_text = mailLanguage.income.income_name;
    }
  },
  mounted() {
    // if(this.$route.name == "new_love_list" ){
    //   listURL = "plugin.new-love.Frontend.Modules.NewLove.Controllers.love-records.index"
    //   pageURL = "plugin.new-love.Frontend.Controllers.page.index"
    // }
    this.selected = "0";
    this.initData();
    
    this.getNetData(0);
    this.customizeIncome();
  },
  components: { cTitle }
};
